package org.springblade.modules.admin.vo.plan;

import cn.hutool.core.convert.Convert;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainPlanTemplate;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zcc
 * @version 1.0
 * @date 2023/2/14 18:10
 */
@Data
public class PlanOtherInfoVo {


	@ApiModelProperty("工单状态")
	private Integer status;

	@ApiModelProperty("保养类型")
	private String planCheckName;

	@ApiModelProperty("逾期天数:false及时,3天表示逾期3天")
	private String time;

	private Date planDate;

	private Date planEndTime;

	public void setPlanEndTime(Date planEndTime) {
		this.planEndTime = planEndTime;
		if (planEndTime == null) {
			this.planEndTime = new Date();
		}
	}

	public void setPlanCheckName(String planCheckName) {
		if(Func.isNotEmpty(planCheckName) && planCheckName.contains("%")){
			List<String> strings = Func.toStrList(planCheckName);
			List<MaintainPlanTemplate> list = new ArrayList<>(10);
			for (String str :strings) {
				String[] split = str.split("%");
				MaintainPlanTemplate maintainPlanTemplate = new MaintainPlanTemplate();
				maintainPlanTemplate.setTemplateName(split[1]);
				maintainPlanTemplate.setSort(Convert.toInt(split[2],0));
				list.add(maintainPlanTemplate);
			}
			List<String> collect = list.stream().sorted(Comparator.comparing(MaintainPlanTemplate::getSort)).map(MaintainPlanTemplate::getTemplateName).collect(Collectors.toList());
			this.planCheckName = String.join(",",collect);
		}else{
			this.planCheckName = planCheckName;
		}
	}
}
